<template>
	<view>
		<view class="mar-top-20 pad-lr-30 bgfff">
			<view class="bord_bootom pad-tb-40 display-sb align-items" @click.stop="openpickydata">
				<view class="display align-items width-80">
					<view class="fontSize-30">产品名称</view>
					<view class="ml60 fontSize-30 col-9">{{dateStr||'请选择'}}</view>
				</view>
				<image src="/static/img/icon8.png" class="icon_right" mode=""></image>
			</view>
			<view class="bord_bootom pad-tb-40 display-sb align-items">
				<view class="display align-items width-80">
					<view class="fontSize-30">机具编号</view>
					<input type="text" class="width-67 ml60 fontSize-30 col-9" v-model="terminal_id" placeholder="请输入机具编号" />
				</view>
				<image src="/static/img/icon9.png" class="proudct-item-icon" @click="saoyisao" mode=""></image>
			</view>
			<view class="bord_bootom pad-tb-40 display-sb align-items">
				<view class="display align-items width-80">
					<view class="fontSize-30">商户名</view>
					<input type="text" v-model="merchant_no" class="width-67 ml60 fontSize-30 col-9" placeholder="请输入商户名" />
				</view>
			</view>
			<view class="pad-tb-30 fontSize-24 col-9">
				注：机具编号就是机子背后的sn号
			</view>
			<view class="tibtn text-align-center col-f fontSize-32 poFi radius-10" @click="_bindingPos">
				提交
			</view>
		</view>
		<tm-picker
			:defaultValue="pickydata"
			@confirm="pickok"
			v-model:show="showdate"
			:columns="pos_brand"
			v-model="pickydata"
			v-model:model-str="dateStr"
			color="#FD6317"
			mapKey="name"
		>
		</tm-picker>
	</view>
</template>

<script lang="ts" setup>
import { onLoad } from '@dcloudio/uni-app';
import { nextTick, ref } from 'vue';
import {posBrand,bindingPos} from '../../utils/api'
onLoad(()=>{
	_posBrand()
})
const _posBrand =() =>{
	posBrand().then(res=>{
		if(res.code==1){
			pos_brand.value = res.data.pos_brand
		}
	})
}
const terminal_id = ref()//机器编号
const merchant_no = ref()//商户名称
const posbrand_id = ref()//产品品牌id
const pos_brand = ref()
const pickydata =ref()
const showdate = ref(false)
const dateStr = ref('')
const openpickydata =()=>{
	showdate.value = true
}
const pickok =()=> {
	nextTick(() => {
		posbrand_id.value = pos_brand.value[pickydata.value].id
		console.log(pickydata.value)
		console.log(dateStr.value)
	})
}
const saoyisao =() =>{
	uni.scanCode({
		success(res) {
			terminal_id.value = res.result
		}
	})
}
const _bindingPos =() =>{
	bindingPos({
		posbrand_id:posbrand_id.value,
		terminal_id:terminal_id.value,
		merchant_no:merchant_no.value
	}).then(res=>{
		uni.showToast({
			title:res.msg,
			icon:'none'
		})
		if(res.code==1){
			
		}
	})
}
</script>

<style lang="scss">
@import 'bind.scss';
</style>
